---
slug: http-proxy-middleware #路径，不能重复
title: http-proxy-middleware # 标题
authors: [] # 作者，在authors.yml配置
tags: [facebook, hello, docusaurus] # 标签，在tags.yml配置
toc_min_heading_level: 2 # 最小展示标题
toc_max_heading_level: 5 # 最大展示标题
---

### http-proxy-middleware

> 配置跨域代理

```js title="src/setupProxy.js"

/**
 * 跨域代理
 */
const {createProxyMiddleware} = require('http-proxy-middleware');
module.exports = function (app) {
    app.use("/api",
        createProxyMiddleware({
            target: 'http://localhost:3000',
            changeOrigin: true,
            ws: true,
            pathRewrite: {
                '^/api': '',
            }
        })
    )
}

```